package com.funny.learning.english;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.facebook.Session;
import com.funny.learning.english.api.TiengAnhApi;
import com.funny.learning.english.api.BaseAjaxCallBack.IAjaxCallbackMMK;
import com.funny.learning.english.util.PlayMusic;
import com.sromku.simple.fb.SimpleFacebook;

public class BaseActivity extends Activity {
	protected LeaningEnglishAppication appication;
	protected BaseActivity activity;

	protected SimpleFacebook mSimpleFacebook;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		appication = (LeaningEnglishAppication) this.getApplication();
		activity = (BaseActivity) this;
	}
	
	protected String getToken(){
		Session session = mSimpleFacebook.getSession();
		
		if (session == null)
			return null;
		
		String accessToken = session.getAccessToken();
		
		return accessToken;
	}

	protected PlayMusic playMusic;

	protected void playMusic(final String srcSound) {
		if (playMusic == null) {
			playMusic = new PlayMusic(activity);
		}
		// final int sRandom = new
		// Random().nextInt(SoundConfig.arrSound.length);
//		new Handler().post(new Runnable() {
//			@Override
//			public void run() {
//				playMusic.play(srcSound);
//			}
//		});
		runOnUiThread(new Runnable() {
			@Override
			public void run() {
				if(srcSound == null || srcSound.equals("")){
					
				}else{
					playMusic.play(srcSound);
				}
			}
		});
	}
	protected void stopMusic() {
		playMusic.stop();
	}

	protected void intAB(String title) {
//		ImageView ivBack = (ImageView) findViewById(R.id.ivBack);
//		TextView tvTitleAB = (TextView) findViewById(R.id.tvTitleAB);
//
//		tvTitleAB.setText(title);
//
//		ivBack.setOnClickListener(new OnClickListener() {
//
//			@Override
//			public void onClick(View arg0) {
//				onBackPressed();
//			}
//		});
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		mSimpleFacebook = SimpleFacebook.getInstance(this);

	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		mSimpleFacebook.onActivityResult(this, requestCode, resultCode, data);
		super.onActivityResult(requestCode, resultCode, data);

	}
	protected void logout(){
		TiengAnhApi.logout(activity, new IAjaxCallbackMMK() {

			@Override
			public <T> void handler(T t, int code) {
				if(code == COMPLETE){
					finish();
				}
			}
		});
	}
}
